Please enable JavaScript to view this website.

Skip to main content

Show me an example

Here is one example of a rework script that connects to an M18 battery and then determines which bin it should be sorted into.

Chart

JSON

{
"StartAt": "Connect via Adapter",
"Comment": "Rework for the M18 Batteries",
"MTSLLanguageVersion": "1.0",
"TimeoutSeconds": 30,
"States": {
"Connect via Adapter": {
"Type": "Task",
"Resource": "Product:Connect",
"Parameters": {
"CommunicationMethod": "CommunicationAdapter",
"Target": "M18Battery"
},
"ResultPath": "$.ConnectionStatus",
"Next": "Read Battery MPBID"
},
"Read Battery MPBID": {
"Type": "Task",
"Resource": "OpenLink:SendCommand",
"Parameters": {
"MessageType": "01",
"IsWrite": false,
"RouteType": "Tool",
"CommandBody": "000405"
},
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Next": "Display Error"
}
],
"ResultSelector": {
"MPBID.$": "States.ByteArrayToString($.OpenLinkCommandResponse.Payload)",
"ProductId.$": "States.SliceAndParseToNumber($.OpenLinkCommandResponse.Payload, 0, 2)",
"SerialId.$": "States.SliceAndParseToNumber($.OpenLinkCommandResponse.Payload, 2, 5)"
},
"Next": "Request Battery Item Instance"
},
"Request Battery Item Instance": {
"Type": "Task",
"Resource": "Network:ApiCall",
"Parameters": {
"BaseUrl": "ManufacturingAPI",
"Method": "GET",
"Path.$": "States.Format('/v1/tool/records?mpbid={}', $.MPBID)"
},
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Next": "Display Error"
}
],
"ResultSelector": {
"ToolRecord.$": "$.records[0]"
},
"Next": "Display Serial Number"
},
"Display Serial Number": {
"Type": "Task",
"Resource": "UI:Display",
"Parameters": {
"Title": "Battery Serial Number",
"Sentiment": "Neutral",
"Value.$": "$.ToolRecord.serialNumber"
},
"ResultPath": "$.SerialNum",
"Next": "Write METCO Password"
},
"Write METCO Password": {
"Type": "Task",
"Resource": "OpenLink:SendCommand",
"Parameters": {
"MessageType": "01",
"IsWrite": true,
"RouteType": "Tool",
"CommandBody.$": "States.Format('003B{}', $.ToolRecord.metcoPassword)"
},
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Next": "Display Error"
}
],
"ResultPath": "$.Auth",
"Next": "Read Cell Balance"
},
"Read Cell Balance": {
"Type": "Task",
"Resource": "OpenLink:SendCommand",
"Parameters": {
"MessageType": "01",
"IsWrite": false,
"RouteType": "Tool",
"CommandBody": "400A0A"
},
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Next": "Display Error"
}
],
"ResultSelector": {
"CellBalance.$": "$.OpenLinkCommandResponse.Payload"
},
"Next": "Calculate Cell Balance"
},
"Calculate Cell Balance": {
"Type": "Task",
"Resource": "Calculation:CellBalance",
"Parameters": {
"ComparatorValue": 100,
"isLittleEndian": false,
"Value.$": "$.CellBalance"
},
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Next": "Display Error"
}
],
"ResultPath": "$.CellBalanceCalculation",
"Next": "Display Cell Balance"
},
"Display Cell Balance": {
"Type": "Choice",
"Choices": [
{
"And": [
{
"Variable": "$.CellBalanceCalculation.IsBalanced",
"StringEquals": "Yes"
}
],
"Next": "Display In Balance"
}
],
"Default": "Display NOT In Balance"
},
"Display In Balance": {
"Type": "Task",
"Resource": "UI:Display",
"Parameters": {
"Title": "Cell Balance",
"Value": "Balanced",
"Sentiment": "Success",
"AdditionalDetails.$": "$.CellBalanceCalculation"
},
"Next": "Load Serial Number"
},
"Display NOT In Balance": {
"Type": "Task",
"Resource": "UI:Display",
"Parameters": {
"Title": "Cell Balance",
"Value": "Unbalanced",
"Sentiment": "Failure",
"AdditionalDetails.$": "$.CellBalanceCalculation"
},
"Next": "Load Serial Number"
},
"Load Serial Number": {
"Type": "Pass",
"Parameters": {
"Model.$": "States.Slice($.ToolRecord.serialNumber, 0, 3)",
"Code.$": "States.Slice($.ToolRecord.serialNumber, 6, 8)"
},
"Next": "Choice"
},
"Choice": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.CellBalanceCalculation.IsBalanced",
"StringEquals": "No",
"Next": "Set Bin Scrap"
},
{
"And": [
{
"Variable": "$.Model",
"StringEquals": "K37"
},
{
"Variable": "$.Code",
"StringEquals": "HC"
}
],
"Next": "Set Bin 1"
},
{
"And": [
{
"Variable": "$.Model",
"StringEquals": "K37"
},
{
"Variable": "$.Code",
"StringEquals": "AF"
}
],
"Next": "Set Bin 2"
},
{
"And": [
{
"Variable": "$.Model",
"StringEquals": "K37"
},
{
"Variable": "$.Code",
"StringEquals": "FE"
}
],
"Next": "Set Bin 3"
},
{
"And": [
{
"Variable": "$.Model",
"StringEquals": "K37"
},
{
"Variable": "$.Code",
"StringEquals": "GB"
}
],
"Next": "Set Bin 4"
},
{
"And": [
{
"Variable": "$.Model",
"StringEquals": "J52"
},
{
"Variable": "$.Code",
"StringEquals": "HC"
}
],
"Next": "Set Bin 5"
},
{
"And": [
{
"Variable": "$.Model",
"StringEquals": "J52"
},
{
"Variable": "$.Code",
"StringEquals": "AF"
}
],
"Next": "Set Bin 6"
},
{
"And": [
{
"Variable": "$.Model",
"StringEquals": "J52"
},
{
"Variable": "$.Code",
"StringEquals": "FE"
}
],
"Next": "Set Bin 7"
},
{
"And": [
{
"Variable": "$.Model",
"StringEquals": "J52"
},
{
"Variable": "$.Code",
"StringEquals": "GB"
}
],
"Next": "Set Bin 8"
}
],
"Default": "Set Bin Other"
},
"Set Bin 1": {
"Type": "Pass",
"Parameters": {
"BinNumber": "1"
},
"Next": "Display Bin Number"
},
"Set Bin 2": {
"Type": "Pass",
"Parameters": {
"BinNumber": "2"
},
"Next": "Display Bin Number"
},
"Set Bin 3": {
"Type": "Pass",
"Parameters": {
"BinNumber": "3"
},
"Next": "Display Bin Number"
},
"Set Bin 4": {
"Type": "Pass",
"Parameters": {
"BinNumber": "4"
},
"Next": "Display Bin Number"
},
"Set Bin 5": {
"Type": "Pass",
"Parameters": {
"BinNumber": "5"
},
"Next": "Display Bin Number"
},
"Set Bin 6": {
"Type": "Pass",
"Parameters": {
"BinNumber": "6"
},
"Next": "Display Bin Number"
},
"Set Bin 7": {
"Type": "Pass",
"Parameters": {
"BinNumber": "7"
},
"Next": "Display Bin Number"
},
"Set Bin 8": {
"Type": "Pass",
"Parameters": {
"BinNumber": "8"
},
"Next": "Display Bin Number"
},
"Set Bin Scrap": {
"Type": "Pass",
"Parameters": {
"BinNumber": "Scrap"
},
"Next": "Display Bin Scrap"
},
"Set Bin Other": {
"Type": "Pass",
"Parameters": {
"BinNumber": "Other"
},
"Next": "Display Bin Number"
},
"Display Bin Number": {
"Type": "Task",
"Resource": "UI:Prompt",
"Parameters": {
"Title": "Bin Number",
"Importance": "High",
"Sentiment": "Neutral",
"Message.$": "States.Format('<div class=\"text-xl\">Please place the battery in bin {}</div>', $.BinNumber)"
},
"Next": "Save Report"
},
"Display Bin Scrap": {
"Type": "Task",
"Resource": "UI:Prompt",
"Parameters": {
"Title": "Bin Number",
"Message": "<div class='text-xl'>Please place the battery in the scrap bin</div>",
"Importance": "High",
"Sentiment": "Failure"
},
"Next": "Save Report"
},
"Display Error": {
"Type": "Task",
"Resource": "UI:Prompt",
"Parameters": {
"Title": "Error",
"Importance": "High",
"Sentiment": "Failure",
"Message": "<div class='text-xl'>There was an error please click on Retry to run the rework again</div>"
},
"End": true
},
"Save Report": {
"Type": "Task",
"Resource": "Network:ApiCall",
"Parameters": {
"BaseUrl": "ToolDataAPI",
"Method": "POST",
"Path": "/tooldata/v1/tooldata/service-instance/rework",
"Body": {
"rework": "M18 Battery Rework",
"serialNumber.$": "$.ToolRecord.serialNumber",
"description.$": "$.ToolRecord.description",
"mpbid.$": "$.MPBID",
"bin.$": "$.BinNumber",
"isBalanced.$": "$.CellBalanceCalculation.IsBalanced"
}
},
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Next": "Display Error"
}
],
"ResultPath": "$.SaveReport",
"End": true
}
}
}